package logic

import (
	"context"

	"newwater/app/user/cmd/rpc/internal/svc"
	"newwater/app/user/cmd/rpc/user"

	"github.com/tal-tech/go-zero/core/logx"
)

type UserInfoByUserNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInfoByUserNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoByUserNameLogic {
	return &UserInfoByUserNameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInfoByUserNameLogic) UserInfoByUserName(in *user.UserName) (*user.UserReply, error) {
	// todo: add your logic here and delete this line

	myuser, err := l.svcCtx.WaterUser.FindOneByUsername(in.Name)
	if err != nil {
		return nil, err
	}
	return &user.UserReply{
		Id: myuser.UserId,
		Username: myuser.UserName,
		Nickname: myuser.NickName,
		Email: myuser.Email,
		Sex: myuser.Sex,
		Phonenumber: myuser.Phonenumber,
	}, nil
}
